/*     */ package com.zimbra.cs.filter.jsieve;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.filter.ZimbraMailAdapter;
/*     */ import com.zimbra.cs.filter.ZimbraSieveException;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.calendar.Util;
/*     */ import java.util.Calendar;
/*     */ import java.util.HashSet;
/*     */ import java.util.List;
/*     */ import java.util.ListIterator;
/*     */ import java.util.Set;
/*     */ import java.util.TimeZone;
/*     */ import org.apache.jsieve.Argument;
/*     */ import org.apache.jsieve.Arguments;
/*     */ import org.apache.jsieve.SieveContext;
/*     */ import org.apache.jsieve.StringListArgument;
/*     */ import org.apache.jsieve.TagArgument;
/*     */ import org.apache.jsieve.exception.SieveException;
/*     */ import org.apache.jsieve.exception.SyntaxException;
/*     */ import org.apache.jsieve.mail.MailAdapter;
/*     */ import org.apache.jsieve.tests.AbstractTest;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CurrentDayOfWeekTest
/*     */   extends AbstractTest
/*     */ {
/*     */   protected boolean executeBasic(MailAdapter mail, Arguments arguments, SieveContext context)
/*     */     throws SieveException
/*     */   {
/*  51 */     if (!(mail instanceof ZimbraMailAdapter)) {
/*  52 */       return false;
/*     */     }
/*  54 */     ListIterator<Argument> argumentsIter = arguments.getArgumentList().listIterator();
/*     */     
/*     */ 
/*  57 */     String comparator = null;
/*  58 */     if (argumentsIter.hasNext()) {
/*  59 */       Object argument = argumentsIter.next();
/*  60 */       if ((argument instanceof TagArgument))
/*  61 */         comparator = ((TagArgument)argument).getTag();
/*     */     }
/*  63 */     if (!":is".equals(comparator)) {
/*  64 */       throw new SyntaxException("Expecting \":is\"");
/*     */     }
/*     */     
/*  67 */     Set<Integer> daysToCheckAgainst = new HashSet();
/*  68 */     if (argumentsIter.hasNext()) {
/*  69 */       Object argument = argumentsIter.next();
/*  70 */       if ((argument instanceof StringListArgument)) {
/*  71 */         List<String> valList = ((StringListArgument)argument).getList();
/*  72 */         for (String val : valList) {
/*     */           int day;
/*     */           try {
/*  75 */             day = Integer.valueOf(val).intValue();
/*     */           } catch (NumberFormatException e) {
/*  77 */             throw new SyntaxException(e);
/*     */           }
/*  79 */           if ((day < 0) || (day > 6)) {
/*  80 */             throw new SyntaxException("Expected values between 0 - 6");
/*     */           }
/*  82 */           daysToCheckAgainst.add(Integer.valueOf(day + 1));
/*     */         }
/*     */       }
/*     */     }
/*  86 */     if (daysToCheckAgainst.isEmpty()) {
/*  87 */       throw new SyntaxException("Expecting at least one value");
/*     */     }
/*     */     
/*  90 */     if (argumentsIter.hasNext()) {
/*  91 */       throw new SyntaxException("Found unexpected argument(s)");
/*     */     }
/*     */     TimeZone accountTimeZone;
/*     */     try {
/*  95 */       accountTimeZone = Util.getAccountTimeZone(((ZimbraMailAdapter)mail).getMailbox().getAccount());
/*     */     } catch (ServiceException e) {
/*  97 */       throw new ZimbraSieveException(e);
/*     */     }
/*  99 */     Calendar rightNow = Calendar.getInstance(accountTimeZone);
/*     */     
/* 101 */     return daysToCheckAgainst.contains(Integer.valueOf(rightNow.get(7)));
/*     */   }
/*     */   
/*     */   protected void validateArguments(Arguments arguments, SieveContext context) {}
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/filter/jsieve/CurrentDayOfWeekTest.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */